package com.itheima.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Slf4j
//@Aspect
public class TimeAspect {
    @Around("execution(* com.itheima.service.*.*(..))")
    public Object calculateTime(ProceedingJoinPoint joinPoint) throws Throwable {
        //开始前时间
        long start = System.currentTimeMillis();

        //调用原始方法
        Object proceed = joinPoint.proceed();

        //结束时间
        long end = System.currentTimeMillis();
        log.info(joinPoint.getSignature() +"耗时：{}ms", end - start);

        return proceed;
    }
}
